package com.woniuxy.service.impl;

import com.alibaba.fastjson.JSON;
import com.woniuxy.entity.Doctor;
import com.woniuxy.entity.Schedule;
import com.woniuxy.mapper.DoctorMapper;
import com.woniuxy.mapper.ScheduleMapper;
import com.woniuxy.producer.DelayExchangeProducer;
import com.woniuxy.service.SaasService;
import com.woniuxy.service.ScheduleService;
import com.woniuxy.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @Author: NoNo
 * @Date: 2024/4/19&17:10
 */
@Service
public class ScheduleServiceImpl implements ScheduleService , SaasService {
    @Autowired
    ScheduleMapper scheduleMapper;
    @Autowired
    DoctorMapper doctorMapper;
    @Autowired
    DelayExchangeProducer delayExchangeProducer;
    @Override
    public ResponseData<?> queryList(Schedule schedule) {
        List<Doctor> doctors = doctorMapper.querySchedule(schedule);
        return new ResponseData<>().ok(doctors);
    }

    @Override
    public ResponseData<?> addSchedule(Doctor doctor) {
        Integer id = doctor.getId();
        String scDate = doctor.getScDate();
        Integer docDeId = doctor.getDocDeId();
        Doctor doctor1 = new Doctor();
        doctor1.setId(id);
        doctor1.setDocDeId(docDeId);
        doctor1.setScStatus(1);
        doctor1.setScTimeSlot(1);
        doctor1.setScDate(scDate);

        String doctor2 = JSON.toJSONString(doctor1);
        delayExchangeProducer.send(doctor2,"addSchedule",0);
        //doctorMapper.addSchedule(doctor1);
        return new ResponseData<>().ok(doctor1);
    }
}
